import axios from 'axios'
import request from "../utils/request"


function ossSignURL(param, component) {

    return request.post(component.uploadImgUrl,
       param
    ).then(res => {
        component.url = res.data.url;
        component.objectName = res.data.objectName;
        console.log("ossSignURL", res);
        return res;
    });
}

/**
 * 
 * @param {{}} url 
 * @param {File} file 
 * @param {Component} component 
 * @returns 
 */
function sendFileToOSS(data, file,component) {
    console.log("file", file, "url");

    let headers =  {
        "Content-Type": data.type,
        "date": component.date
    };

    return axios.put(data.url, file,  {
        headers: headers
    }).then(res => {

        console.log("sendFileToOSS", res);

        return res;

    }) 
}

/**
 * 删除oss对象
 * @param {String} file 
 * @returns 
 */
function deleteFileFromOss(file) {
    

    return request.post("/oss/delete", {
        fileName: file
    }).then(res => {

        console.log("sendFileToOSS", res);
        return res;

    }) 
}


export {
    ossSignURL,
    deleteFileFromOss,
    sendFileToOSS
}